<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 200px;
            height: 200px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
    <div data-price="100"></div>
    <input type="button" value="读取" id="read">
    <input type="button" value="设置" id="write">

    <script>
        var btnread=document.querySelector('#read');
        btnread.onclick=function(){
            var div1=document.querySelector('div');
            // alert(div1.getAttribute('data-price'));

            // alert(div1.dataset.price);
            alert(div1.dataset['price']);
        }

        var btnread=document.querySelector('#write');
        btnread.onclick=function(){
            var div1=document.querySelector('div');
            var wri=prompt('请输入数值');
            div1.getAttribute('data-price',wri);
            // div1.dataset.price=wri;
            // div1.dataset['price']=wri;
        }
    </script>
</body>
</html>